package TUILayer;
import ControlLayer.*;
import java.util.Scanner;

/**
 * Write a description of class BorrowUI here.
 * 
 * @author Rasmus Andersen Borup 
 * @version 
 */
public class BorrowUI
{
    // instance variables
    private BorrowCtr borrowCtr;

    /**
     * Constructor for objects of class BorrowUI
     */
    public BorrowUI()
    {
        // initialising instance variables
        borrowCtr = new BorrowCtr(); 
    }

    public void start()
    {
        borrowMenu();
    }
    
    private void borrowMenu()
    {
        boolean exit = false;
        while(!exit)//that is: while exit is false
        {
            int choice = writeBorrowMenu(); 
            if(choice == 1)
            {   //Show person info
                createBorrow();
            }
            else{
                if(choice == 2)
                {
                    //Add person
                    deleteBorrow();
                }  
                else
                {
                    exit = true;
                }//end else
            }//end else
            
        }//end while
    }
    
    private int writeBorrowMenu()
    {      // makes an object keyboard to read input from the screen
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** AddressBook Menu ***");
        System.out.println(" (1) New borrow");
        System.out.println(" (2) Delete borrow");
        System.out.println(" (3) Return");
        System.out.print("\n Make your choice: ");
        
        int choice = keyboard.nextInt();
        return choice;
    }
    
    private int inputDvdId()
    {
         // makes an object keyboard to have input from the screen
         Scanner keyboard = new Scanner(System.in);  
         System.out.println("Write dvds id: ");
         int id = Integer.parseInt(keyboard.nextLine());
         return id;
    }
    
    private long inputPersonId()
    {
         // makes an object keyboard to have input from the screen
         Scanner keyboard = new Scanner(System.in);  
         System.out.println("Write borrowers id: ");
         long id = Long.parseLong(keyboard.nextLine());
         return id;
    }
    
    private String inputBorrowDate()
    {
        // makes an object keyboard to read input from the console
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Write date: ");
        String date = keyboard.nextLine();
        return date;
    }
    
    private String inputBorrowPeriod()
    {
        // makes an object keyboard to read input from the console
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Write borrow period: ");
        String period = keyboard.nextLine();
        return period;
    }
    
    private String inputBorrowStatus()
    {
        // makes an object keyboard to read input from the console
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Write status: ");
        String status = keyboard.nextLine();
        return status;
    }
    
    private void createBorrow()
    {
        borrowCtr.addBorrow(inputPersonId(), inputDvdId(), inputBorrowDate(), inputBorrowPeriod(), inputBorrowStatus());
    }
    
    private void deleteBorrow()
    {
        borrowCtr.deleteBorrow(inputDvdId());
    }
}
